package com.candoit.webapps.pricing.bean.adapters;

import java.util.List;

import javax.faces.model.SelectItem;
import javax.persistence.EntityManager;

import com.candoit.webapps.pricing.bean.PricingContext;

public abstract class GenericAdapter {
	
	protected List<SelectItem> items;

	public abstract List<SelectItem> getItems();
	
	protected GenericConverter converter;
	
	protected List list;

	public void setItems(List<SelectItem> items) {
		this.items = items;
	}
	
	public abstract String getClase();
	
	public abstract String getFieldId();
	
	public abstract GenericConverter getConverter();
	
	protected String getQuery(String clase){
		return "select c from " + clase + " c "; 
	}
	
	public List retrieve() {
		EntityManager em = PricingContext.getInstance().getEntityManager();
		list = em.createQuery(getQuery(getClase())).getResultList();
		return list;
	}


}
